package com.oa.ylms.apps.dao.notice.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oa.ylms.apps.dao.notice.INoticeSectionDao;
import com.oa.ylms.apps.entity.notice.NoticeSectionValue;

@SuppressWarnings("unchecked")
public class NoticeSectionDaoImpl extends HibernateDaoSupport implements
		INoticeSectionDao {

	public int addNoticeSection(NoticeSectionValue noticeSection)
			throws Exception {
		if (noticeSection != null) {
			this.getHibernateTemplate().save(noticeSection);
			return noticeSection.getId();
		}
		return 0;
	}

	public boolean deleteNoticeSection(NoticeSectionValue noticeSection)
			throws Exception {
		if (noticeSection != null) {
			try {
				this.getHibernateTemplate().delete(noticeSection);
			} catch (Exception e) {
				return false;
			}
		}
		return false;
	}

	public List<NoticeSectionValue> queryNoticeSectionByNoticeId(int noticeId)
			throws Exception {
		return this.getHibernateTemplate().find(
				"select nsv from NoticeSectionValue nsv,SectionInfoValue siv where nsv.sectionInfo.sectionId = siv.sectionId AND nsv.noticeInfo.noticeId =? ", noticeId);
	}

}
